import rxAjax from '@/assets/js/ajax.js';

//业务实体 api接口
export const FormBoEntityApi = {};

FormBoEntityApi.baseUrl= '/api-form/form/bo/formBoEntity';
FormBoEntityApi.exportUrl= FormBoEntityApi.baseUrl + '/listExport';

//查询列表
FormBoEntityApi.query=function (parameter) {
  var url= FormBoEntityApi.baseUrl + '/query';
  return rxAjax.postJson(url,parameter).then (res => {
    return res.result
  })
}

/**
* 获取单记录
* @param pkId
* @returns {*}
*/
FormBoEntityApi.get =function(pkId) {
  var url= FormBoEntityApi.baseUrl + '/get?pkId=' + pkId;
  return rxAjax.get(url);
}

//保存数据
FormBoEntityApi.save =function(parameter) {
  var url= FormBoEntityApi.baseUrl + '/save';
  return rxAjax.postJson(url,parameter);
}

//删除数据
FormBoEntityApi.del =function(parameter) {
  var url= FormBoEntityApi.baseUrl + '/delBoEntity';
  return rxAjax.postUrl(url,parameter);
}

//生成物理表
FormBoEntityApi.creatBoTable=function(pkId){
  var url = FormBoEntityApi.baseUrl + '/creatBoTable?pkId='+pkId;
  return rxAjax.get(url);
}

//删除物理表
FormBoEntityApi.deleteBoTable=function(pkId,tableName){
  var url = FormBoEntityApi.baseUrl + '/deleteBoTable?pkId='+pkId+"&tableName="+tableName;
  return rxAjax.get(url);
}


//保存实体
FormBoEntityApi.saveBoEnt = function (parameter,directlySave) {
    var url = FormBoEntityApi.baseUrl + '/saveBoEnt';
    if(directlySave){
        url+="?directlySave="+directlySave;
    }
  return rxAjax.postJson(url, parameter);
}

FormBoEntityApi.getBoEnt = function (pkId,boAttrTemp) {
  var url = FormBoEntityApi.baseUrl + '/getBoEnt?pkId=' + pkId;
  if(boAttrTemp){
      url+="&boAttrTemp="+boAttrTemp;
  }
  return rxAjax.get(url);
}

FormBoEntityApi.getFieldByBoDefId = function (boDefId, entName) {
  var url = FormBoEntityApi.baseUrl + '/getFieldByBoDefId?boDefId=' + boDefId + '&tableName=' + entName;
  return rxAjax.get(url);
}

FormBoEntityApi.getMainExcludeAttrsByBoDefId=function(boDefId){
  var url = FormBoEntityApi.baseUrl + '/getMainExcludeAttrsByBoDefId?boDefId='+boDefId;
  return rxAjax.get(url);
}


FormBoEntityApi.getPinyin =function(chinese) {
    var url= "/api-form/form/share/pinyin/getPinyin";
    var params={chinese:chinese,lower:true};
    return rxAjax.postForm(url,params);
}


//暂存
FormBoEntityApi.temporarySave = function (parameter) {
    var url = FormBoEntityApi.baseUrl + '/temporarySave';
    return rxAjax.postJson(url, parameter);
}

//解绑物理表
FormBoEntityApi.unboundTable=function(pkId,tableName){
    var url = FormBoEntityApi.baseUrl + '/unboundTable?pkId='+pkId;
    return rxAjax.get(url);
}

FormBoEntityApi.saveList=function(parameter){
    var url = FormBoEntityApi.baseUrl + '/saveList';
    return rxAjax.postJson(url,parameter);
}


FormBoEntityApi.batchChangesApp=function(parameter){
    var url = FormBoEntityApi.baseUrl + '/batchChangesApp';
    return rxAjax.postJson(url,parameter);
}

//获取表索引
FormBoEntityApi.getTableIndex=function(pkId){
    var url = FormBoEntityApi.baseUrl + '/getTableIndex?pkId='+pkId;
    return rxAjax.get(url);
}

//删除表索引
FormBoEntityApi.delTableIndex=function(pkId,keyName){
    var url = FormBoEntityApi.baseUrl + '/delTableIndex?pkId='+pkId+"&keyName="+keyName;
    return rxAjax.get(url);
}

//创建索引
FormBoEntityApi.createdIndex=function(parameter){
    var url = FormBoEntityApi.baseUrl + '/createdIndex';
    return rxAjax.postJson(url,parameter);
}

FormBoEntityApi.update=function(parameter){
    var url = FormBoEntityApi.baseUrl + '/update';
    return rxAjax.postJson(url,parameter);
}

//切换导出
FormBoEntityApi.updExport=function(ids){
    var url= FormBoEntityApi.baseUrl+'/updExport';
    return rxAjax.postForm(url, {ids:ids});
}

//变更分类
FormBoEntityApi.changeCategory=function(ids,categoryId){
    var url= FormBoEntityApi.baseUrl+'/changeCategory';
    return rxAjax.postForm(url, {ids:ids,categoryId:categoryId});
}
export default FormBoEntityApi;

